package com.zr.shortlink.admin.controller;

import com.zr.shortlink.admin.common.result.Result;
import com.zr.shortlink.admin.common.result.Results;
import com.zr.shortlink.admin.dto.req.ShortLinkGroupSaveReqDTO;
import com.zr.shortlink.admin.dto.req.ShortLinkGroupSortReqDTO;
import com.zr.shortlink.admin.dto.req.ShortLinkGroupUpdateReqDTO;
import com.zr.shortlink.admin.dto.resp.ShortLinkGroupRespDTO;
import com.zr.shortlink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短链接分组控制层
 */
@RestController
@RequiredArgsConstructor
public class GroupController {
    private final GroupService groupService;

    /**
     * 新增短链接分组
     * @param requestparam
     * @return
     */
    @PostMapping("api/short-link/admin/v1/group")
    public Result<Void> save(@RequestBody ShortLinkGroupSaveReqDTO requestparam){
        groupService.saveGroup(requestparam.getName());
        return Results.success();
    }

    /**
     * 查询短链接分组集合
     *
     */
    @GetMapping("api/short-link/admin/v1/group")
    public Result<List<ShortLinkGroupRespDTO>> listgroup(){
        return Results.success(groupService.listGroup());
    }

    /**
     * 修改短链接分组名称
     * @param requestparam
     * @return
     */
    @PutMapping("api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO requestparam){
        groupService.UpdateGroup(requestparam);
        return Results.success();
    }

    /**
     * 删除短链接分组
     * @param
     * @return
     */
    @DeleteMapping("api/short-link/admin/v1/group")
    public Result<Void> deleteGroup(@RequestParam String gid){
        groupService.Delete(gid);
        return Results.success();
    }

    /**
     * 排序短链接分组
     * @param requestparam
     * @return
     */

    @PostMapping("api/short-link/admin/v1/group/sort")
    public Result<Void> SortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> requestparam){
        groupService.SortOrder(requestparam);
        return Results.success();
    }
}
